package com.study.group.modules.mongo.controller;

import com.study.group.common.entrty.Person;
import com.study.group.common.result.ResponseResult;
import com.study.group.modules.mongo.service.PersonService;
import com.study.group.modules.mongo.service.PersonService2;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Description mongodb 测试类
 * @Author      yanghanwei
 * @Mail        yanghanwei@geotmt.com
 * @Date        2019/4/26 11:59
 * @Version     v1
 **/
@RequestMapping(value = "/group/mongo/person")
@RestController
public class PersonController {

    @Resource
    private PersonService personService;

    @Resource
    private PersonService2 personService2;

    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public ResponseResult list(){
        List<Person> list = personService.list();
        return ResponseResult.build(HttpServletResponse.SC_OK, "查询成功", list, true);
    }
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public ResponseResult save(){
        Person person = new Person("王毅", 11, "男");
        Person save = personService.save(person);
        return ResponseResult.build(HttpServletResponse.SC_OK, "查询成功", save, true);
    }
    @RequestMapping(value = "/getById", method = RequestMethod.POST)
    public ResponseResult getById(){
        Person byId = personService.getById("5cb1954b935bc2b4a4a5c836");
        return ResponseResult.build(HttpServletResponse.SC_OK, "查询成功", byId, true);
    }
    @RequestMapping(value = "/getByName", method = RequestMethod.POST)
    public ResponseResult getByName(){
        List<Person> list = personService.getByName("王毅");
        return ResponseResult.build(HttpServletResponse.SC_OK, "查询成功", list, true);
    }
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public ResponseResult update(){
        Integer update = personService.update(new Person());
        return ResponseResult.build(HttpServletResponse.SC_OK, "查询成功", update, true);
    }
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public ResponseResult delete(){
        List<Person> list = personService.list();
        return ResponseResult.build(HttpServletResponse.SC_OK, "查询成功", list, true);
    }
    @RequestMapping(value = "/deleteById", method = RequestMethod.POST)
    public ResponseResult deleteById(){
        List<Person> list = personService.list();
        return ResponseResult.build(HttpServletResponse.SC_OK, "查询成功", list, true);
    }


    @RequestMapping(value = "/listAll", method = RequestMethod.POST)
    public ResponseResult listAll(){
        List<Person> list = personService2.listAll();
        return ResponseResult.build(HttpServletResponse.SC_OK, "查询成功", list, true);
    }



}
